/*************************************************
Author: will
Date: 9/11/2012
Description:
Notes: 
*************************************************/

#ifndef __CTaskConfig_h__
#define __CTaskConfig_h__

#include "CTArray.h"
#include "CTaskID.h"
#include "CTaskCond.h"
#include "CTaskDef.h"
#include "TaskAward.h"

class CTaskConfig;

//任务配置项
class CTaskConfigData
{
    friend class CTaskConfig;
public:

	CTaskConfigData() 
        :_bHasConfig(false)
    {
	}

	virtual ~CTaskConfigData() 
    {
	}

    void Clear() {_bHasConfig = false;}
    bool HasConfig() const {return _bHasConfig;}
    bool IsDirectAccept() const {return _astOpenConds.Size() == 0;}
    bool NeedOpen() const {return _astOpenConds.Size() > 0;}
    unsigned int GetBranchID() const {return _stTaskID._uiBranchID;}
    unsigned int GetTaskID() const {return _stTaskID._uiTaskID;}
    bool IsMainTask() const {return _stTaskID.IsMainTask();}
    bool IsValidBranchID(unsigned int uiMaxBranchID) const {return GetBranchID() <= uiMaxBranchID;}
    bool IsValidMainTaskID(unsigned int uiMaxMainTaskID) const {return GetTaskID() <= uiMaxMainTaskID;}

    //是否是循环任务
    bool IsCyclicTask() const
    {
        return (_stTaskID.IsLessonTask() || _stTaskID.IsRewardTask());
    }

public:
    bool _bHasConfig;       //该config对象是否有有效值
    CTaskID _stTaskID;      
    int  _iAcceptNPC;       //领取任务NPC
    int  _iCommitNPC;       //提交任务NPC

    CTLib::CTArray<CTaskCond, MAX_TASK_OPEN_COND>   _astOpenConds;              //激活条件
    CTLib::CTArray<CTaskCond, MAX_TASK_FINISH_COND> _astFinishConds;            //完成条件   
    CTLib::CTArray<CTaskID, MAX_TASK_FOLLOW>        _astFollowTasks;            //后续任务
    CTLib::CTArray<CTaskAward, MAX_TASK_AWARD>	    _astTaskAward;		//award for task finish

    int _usInstanceID;               //用来查找的副本ID
};

//任务配置
class CTaskConfig
{
public:
	CTaskConfig() 
    {
	}

	virtual ~CTaskConfig() 
    {
	}

    int Init();

    int AddConfig(CTaskConfigData& stConfigData);

    int GetMainConfig(unsigned int uiTaskID, CTaskConfigData& stConfigData);

    int GetBranchConfig(unsigned int uiBranchID, unsigned int uiTaskID, CTaskConfigData& stConfigData);

    int GetConfig(CTaskID& stTaskID, CTaskConfigData& stConfigData);

private:

    CTLib::CTArray<CTaskConfigData, MAX_MAIN_TASK_CONFIG>                           _astMainTaskConfigs;        //主任务配置
    CTLib::CTArray<CTaskConfigData, MAX_TASK_CONFIG_PER_BRANCH * MAX_TASK_BRANCHS>      _astBranchTaskConfigs;      //分支任务配置
};

#endif // __CTaskConfig_h__

